package com.shuda.db.user.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shuda.db.user.dao.UserDao;
import com.shuda.db.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDbService {
    
    @Autowired
    private UserDao userDao;
    
    @Cacheable(value = "users", key = "#id")
    public User getById(Long id) {
        return userDao.getById(id);
    }
    
    @Cacheable(value = "users", key = "#username")
    public User getByUsername(String username) {
        return userDao.getByUsername(username);
    }
    
    public List<User> getList(Page<User> page) {
        return userDao.getList(page);
    }
    
    public int insert(User user) {
        return userDao.insert(user);
    }
    
    public int update(User user) {
        return userDao.update(user);
    }
    
    public int delete(Long id) {
        return userDao.delete(id);
    }
    
    public boolean existsByUsername(String username) {
        return userDao.existsByUsername(username);
    }
}